package com.wu.controller;

import com.wu.entity.ShiroUser;
import com.wu.service.impl.UserService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author wuyanshen
 * @date 2019-01-13 7:44 PM
 * @discription 描述
 */
@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequiresRoles({"ADMIN"})
    @RequestMapping(value = "list",method = RequestMethod.GET)
    public String get(HttpSession session, Model model) {
        session.setAttribute("key","123456");
        model.addAttribute("msg", "abce");
        userService.get(new ShiroUser());
        return "list";
    }

    @RequestMapping(value = "/goUser", method = {RequestMethod.GET})
    public String goUser(HttpServletRequest request,Model model) {
        ShiroUser user = new ShiroUser();
        user.setId("1");
        ShiroUser shiroUser = userService.get(user);
        model.addAttribute("user", shiroUser);
        return "user";
    }

    @RequestMapping(value = "/goAdmin", method = {RequestMethod.GET})
    public String goAdmin(HttpServletRequest request) {
        return "admin";
    }

}
